package cn.coisini.api.admin;

import cn.coisini.model.common.dtos.Result;
import cn.coisini.model.common.enums.ResultEnum;
import cn.coisini.model.dto.UserDto;
import cn.coisini.model.pojo.User;
import cn.coisini.model.vo.AssginRoleVo;
import cn.coisini.model.vo.QueryVo;
import cn.coisini.model.vo.UserVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author xiangshaw
 * Description: 用户接口API
 */
@Tag(name = "用户接口API", description = "登录、注册、查询 等等")
@RequestMapping("/api/v1/user")
@Validated
public interface UserControllerApi {

    @PreAuthorize("hasAuthority('user:list')")
    @Operation(summary = "用户列表")
    @GetMapping("/list")
    Result<Object> pagingQuery(QueryVo queryVo);

    @PreAuthorize("hasAuthority('user:findById')")
    @Operation(summary = "根据用户id查询用户信息")
    @GetMapping("/findById")
    Result<UserDto> findUserById(@RequestBody UserVo userVo);

    @PreAuthorize("hasAuthority('user:list')")
    @Operation(summary = "根据用户id列表查询用户信息")
    @GetMapping("/findByIds")
    List<User> findUserByIds(@RequestBody UserVo userVo);

    @PreAuthorize("hasAuthority('user:list')")
    @Operation(summary = "根据用户ID列表批量获取用户信息，并以用户ID为键构建Map")
    @GetMapping("/getUserMapByIds")
    Map<String, User> getUserMapByIds(@RequestBody UserVo userVo);

    @PreAuthorize("hasAuthority('user:remove')")
    @Operation(summary = "删除用户")
    @DeleteMapping("/remove/{id}")
    Result<ResultEnum> remove(@PathVariable("id") String id);

    @PreAuthorize("hasAuthority('user:batchRemove')")
    @Operation(summary = "批量删除用户")
    @DeleteMapping("/batchRemove")
    Result<ResultEnum> batchRemove(@RequestBody List<String> ids);

    @PreAuthorize("hasAuthority('user:add')")
    @Operation(summary = "添加用户")
    @PostMapping("/add")
    Result<ResultEnum> addUser(@RequestBody UserDto userDto);

    // 修改用户
    @PreAuthorize("hasAuthority('user:update')")
    @Operation(summary = "用户信息更新")
    @PutMapping("/updates")
    Result<ResultEnum> updateUser(@RequestBody UserDto userDto);

    @Operation(summary = "用户信息更新")
    @PreAuthorize("hasAuthority('user:update')")
    @PutMapping("/update")
    Result<ResultEnum> updateUserInfo(@RequestBody UserDto userDto);

    @Operation(summary = "用户状态更新")
    @PreAuthorize("hasAuthority('user:status')")
    @PatchMapping("/status")
    Result<ResultEnum> updateUserStatus(@RequestBody UserVo userVo);

    @Operation(summary = "获取用户信息")
    @GetMapping("/info")
    Result<Map<String, Object>> findByUsername();

    @Operation(summary = "用户头像更新")
    @PreAuthorize("hasAuthority('user:update')")
    @PatchMapping("/avatar")
    Result<ResultEnum> updateUserAvatar(@RequestBody UserVo userVo);

    @Operation(summary = "用户密码更新")
    @PreAuthorize("hasAuthority('user:update')")
    @PatchMapping("/password")
    Result<ResultEnum> updateUserPassword(@RequestBody UserVo userVo);

    @Operation(summary = "用户绑定手机号")
    @PreAuthorize("hasAuthority('user:update')")
    @PatchMapping("/bindPhone")
    Result<ResultEnum> bindPhone(@RequestBody UserVo userVo);

    @Operation(summary = "核查用户手机号")
    @GetMapping("/checkPhone/{phone}")
    boolean checkUserPhone(@PathVariable("phone") String phone);

    @Operation(summary = "根据用户id获取角色信息数据")
    @PreAuthorize("hasAuthority('user:getRole')")
    @GetMapping("/toAssign/{id}")
    Result<Map<String, Object>> getRolesByUserId(@PathVariable("id") String id);

    @PreAuthorize("hasAuthority('user:assignRole')")
    @Operation(summary = "给用户分配角色")
    @PostMapping("/doAssign")
    Result<ResultEnum> doAssign(@RequestBody AssginRoleVo assginRoleVo);

}
